function createRedDuckClient(config, id, username) {
	let peer = new Peer()
	let client = {
		peer: peer,
		connection: undefined,
		id: id,
		username: username,
		send(data) {
			if (client.connection)
				client.connection.send(data)
		},
		start() {
			peer.reconnect()
		},
		close() {
			if (connection)
				connection.close()
			peer.disconnect()
		},
		destroy() {
			peer.destroy()
		}
	}
	peer.on('open', function (clientId) {
		client.connection = peer.connect(id)
		client.connection.on('open', function () {
			console.log('Connection is open')
			toast('Client is open.', 'info')
			config.open(client)
			client.connection.send(config.handshakeCommand + username)
		})
		client.connection.on('data', function (data) {
			console.log('Received from server Id:', id, 'data:', data)
			config.data(client, data)
		})
		client.connection.on('error', function (err) {
			console.error('Connection error:', err)
			toast(JSON.stringify(err), 'error', 'Connection Error')
		})
		console.log('Peer is open. Id:', clientId)
	})
	peer.on('close', function () {
		console.log('Peer closed')
		toast('Client is closed.', 'info')
	})
	peer.on('error', function (err) {
		console.error('Peer error:', err)
		toast(JSON.stringify(err), 'error', 'Peer Error')
	})
	return client
}